#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>
#include <unistd.h>
#include "log.hpp"
#include <functional>
enum
{
    OPEN_ERROR = 1
};
class dict {

public:
    dict(const char* path)
    {
        inputFile.open(path);
        if (inputFile.is_open()) {
            loaddate();
        }
        else {
        }
        inputFile.close();

    }
    ~dict() {

    }
    std::string translate(std::string key) {
       if(key.empty()) return "None";
        auto iter = date.find(key);
        if(iter == date.end()) return "None";
        else return iter->second;
    }
private:
    void loaddate() {
        std::string temp;
        int i = 0;
        while (std::getline(inputFile, temp)) {
            if (temp.empty())
                continue;
            int np3 = temp.find_first_of(':');
            std::string key_s = temp.substr(0, np3);
            std::string va_s;
            i = temp.size() - 1;
            if (i>(np3+2))
                va_s = temp.substr(np3 + 2,i);
            else
            date.insert(std::make_pair(key_s, "none trans"));
            date.insert(std::make_pair(key_s, va_s));
        }
    }
private:
    std::unordered_map<std::string, std::string> date;
    std::ifstream inputFile;
};
